% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils_locate_by_id.R
\name{locate_by_id}
\alias{locate_by_id}
\alias{get_facility_info_via_FRS}
\title{query FRS API to find EPA facilities by registry ID or program ID}
\usage{
locate_by_id(id, type = "frs", ...)
}
\arguments{
\item{id}{vector of one or more character strings that must be
registry IDs (default) or program IDs}

\item{type}{either frs (default) or program.
frs means all are registry_id and
program means all are pgm_sys_id}

\item{...}{passed through to \code{\link[=locate_by_id1]{locate_by_id1()}}}
}
\value{
data.frame with one row per queried id, columns as returned by API
but lat lon instead of Latitude83 Longitude83
}
\description{
Uses the Facility Registry Service (FRS) API to find sites by ID.
This uses an API to find sites, but it is faster to look in a table
if that FRS dataset is already loaded in an app, for example.
}
\examples{
  \dontrun{
    
  ids <- testids_program_sys_id
  # ids <- c('ILR000128264','600039382','TXR1592DZ','TSCA8851', 
  #    'CT0000000900908716', 'CEDRI10043548',  'CO0000000812305826')
  # ids <- c('ILR000128264','600039382')
  locate_by_id(ids, type = 'program')   # stopped working   ***********
   
 sites_found_by_registry_id <- locate_by_id(testids_registry_id[1],    
   type='frs')
 sites_found_by_program_id  <- locate_by_id(testids_program_sys_id[1], 
   type='program')
 data.frame(example_REGID  <- t(sites_found_by_registry_id))
 data.frame(example_PGMID  <- t(sites_found_by_program_id))
 # Finding several facilities is slow:
 sites_found_by_registry_id <- locate_by_id(testids_registry_id,    
   type='frs')
 sites_found_by_program_id  <- locate_by_id(testids_program_sys_id, 
   type='program')
 names(sites_found_by_program_id) 
 sites_found_by_registry_id[,c('RegistryId', 'lon','lat')]
 ## and  just to show agreement:  
 cbind(
  testids_program_sys_id,
  frs =  frs[match(
    sites_found_by_program_id$RegistryId, 
     frs$REGISTRY_ID
    ), 
    c('PGM_SYS_ACRNMS',  'REGISTRY_ID')],
  api = sites_found_by_program_id[, c('RegistryId', 'lat', 'lon')] 
 )
 
 # Leaflet map of sites, with a popup when one clicks on a site
 df <- sites_found_by_registry_id
 others <-  frs[sample(1:NROW( frs), 5000), 
  c('lon', 'lat')]
   leaflet::leaflet(df[4:6,]) |> leaflet::addTiles() |>
     leaflet::addMarkers(popup = popup_from_df(df[4:6,])) |>
     leaflet::addCircles(lng = others$lon, lat=others$lat, 
       radius = 3*meters_per_mile, color = 'gray')
      
# Map with clickable icons   
leaflet::leaflet(df) |> leaflet::addTiles() |> 
# leaflet::addCircleMarkers(lng=~lon, lat=~lat, radius = 3) |>
 leaflet::addMarkers(popup = popup_from_df(df), 
 icon = icons(iconUrl = './www/factory1.svg', 
   iconWidth = 30, iconAnchorX = 14, iconAnchorY = 18)
 )
  # Simple map of sites queried (among a sample of US EPA-regulated sites):
    
 xl <- c(-125,-66); yl <- c(17,50) # just continental US plus PR 
 plot( frs[sample(1:NROW(  frs),5000),c('lon','lat')],
  xlim=xl, ylim=yl, col='gray')
 graphics::points(cbind(
  LONG=sites_found_by_program_id$lon, 
  LAT=sites_found_by_program_id$lat), 
  col='red', pch=16)
 }
 
}
\seealso{
\code{\link[=locate_by_id1]{locate_by_id1()}} and alias is \code{\link[=get_facility_info_via_FRS]{get_facility_info_via_FRS()}}
}
\keyword{internal}
